< previous page page_342 next page >

Page 342
e10a6a0a59f035e870d90cca05b85fce.gif
                ' There is no solution. 
                GaussianEliminate = False 
                Exit Function 
            End If 
        End If 
         
        ' Divide each entry in this row by 
        ' coeff(row, row). 
        For i = 0 To max_col 
            coeff(row, i) = coeff(row, i) / factor 
        Next i 

        ' Subtract this row from the others. 
        For i = 0 To max_row 
            If i <> row Then 
                 ' See what factor we will multiply 
                 ' by before subtracting for this row. 
                 factor = coeff(i, row) 
                 For j = 0 To max_col 
                     coeff(i, j) = coeff(i, j) - _ 
                         factor * coeff(row, j) 
                 Next j 
            End If 
        Next i 
    Next row 

    ' There is a solution. 
    GaussianEliminate = True 
End Function

' Find the value of the polynomial with the given 
' coefficients. 
  Private Function PolynomialValue(a_values() As Single, _ 
      ByVal X As Single) As Single 
Dim max_coeff As Integer 
Dim total As Single 
Dim i As Integer 
Dim x_power As Single 

    max_coeff = UBound(a_values) 
    x_power = 1# 
    For i = 0 To max_coeff 
        total = total + x_power * a_values(i) 
        x_power = x_power * X 
    Next i 

    PolynomialValue = total 
End Function
Note that there is no reason to use a polynomial with a degree greater than or equal to the number of points. For example, if you select three points, they can be connected exactly

 
< previous page page_342 next page >